// Code generated by ent, DO NOT EDIT.

package ent

import (
	"context"
	"errors"
	"fmt"
	"server/components/models/ent/forecast"
	"server/components/models/ent/predicate"
	"server/components/models/ent/region"
	"server/components/models/ent/weather"
	"time"

	"entgo.io/ent/dialect/sql"
	"entgo.io/ent/dialect/sql/sqlgraph"
	"entgo.io/ent/schema/field"
)

// ForecastUpdate is the builder for updating Forecast entities.
type ForecastUpdate struct {
	config
	hooks    []Hook
	mutation *ForecastMutation
}

// Where appends a list predicates to the ForecastUpdate builder.
func (fu *ForecastUpdate) Where(ps ...predicate.Forecast) *ForecastUpdate {
	fu.mutation.Where(ps...)
	return fu
}

// SetTemperature sets the "temperature" field.
func (fu *ForecastUpdate) SetTemperature(f float64) *ForecastUpdate {
	fu.mutation.ResetTemperature()
	fu.mutation.SetTemperature(f)
	return fu
}

// SetNillableTemperature sets the "temperature" field if the given value is not nil.
func (fu *ForecastUpdate) SetNillableTemperature(f *float64) *ForecastUpdate {
	if f != nil {
		fu.SetTemperature(*f)
	}
	return fu
}

// AddTemperature adds f to the "temperature" field.
func (fu *ForecastUpdate) AddTemperature(f float64) *ForecastUpdate {
	fu.mutation.AddTemperature(f)
	return fu
}

// SetWindSpeed sets the "windSpeed" field.
func (fu *ForecastUpdate) SetWindSpeed(f float64) *ForecastUpdate {
	fu.mutation.ResetWindSpeed()
	fu.mutation.SetWindSpeed(f)
	return fu
}

// SetNillableWindSpeed sets the "windSpeed" field if the given value is not nil.
func (fu *ForecastUpdate) SetNillableWindSpeed(f *float64) *ForecastUpdate {
	if f != nil {
		fu.SetWindSpeed(*f)
	}
	return fu
}

// AddWindSpeed adds f to the "windSpeed" field.
func (fu *ForecastUpdate) AddWindSpeed(f float64) *ForecastUpdate {
	fu.mutation.AddWindSpeed(f)
	return fu
}

// ClearWindSpeed clears the value of the "windSpeed" field.
func (fu *ForecastUpdate) ClearWindSpeed() *ForecastUpdate {
	fu.mutation.ClearWindSpeed()
	return fu
}

// SetPrecipitationAmount sets the "precipitationAmount" field.
func (fu *ForecastUpdate) SetPrecipitationAmount(f float64) *ForecastUpdate {
	fu.mutation.ResetPrecipitationAmount()
	fu.mutation.SetPrecipitationAmount(f)
	return fu
}

// SetNillablePrecipitationAmount sets the "precipitationAmount" field if the given value is not nil.
func (fu *ForecastUpdate) SetNillablePrecipitationAmount(f *float64) *ForecastUpdate {
	if f != nil {
		fu.SetPrecipitationAmount(*f)
	}
	return fu
}

// AddPrecipitationAmount adds f to the "precipitationAmount" field.
func (fu *ForecastUpdate) AddPrecipitationAmount(f float64) *ForecastUpdate {
	fu.mutation.AddPrecipitationAmount(f)
	return fu
}

// ClearPrecipitationAmount clears the value of the "precipitationAmount" field.
func (fu *ForecastUpdate) ClearPrecipitationAmount() *ForecastUpdate {
	fu.mutation.ClearPrecipitationAmount()
	return fu
}

// SetWeatherCondition sets the "weatherCondition" field.
func (fu *ForecastUpdate) SetWeatherCondition(fc forecast.WeatherCondition) *ForecastUpdate {
	fu.mutation.SetWeatherCondition(fc)
	return fu
}

// SetNillableWeatherCondition sets the "weatherCondition" field if the given value is not nil.
func (fu *ForecastUpdate) SetNillableWeatherCondition(fc *forecast.WeatherCondition) *ForecastUpdate {
	if fc != nil {
		fu.SetWeatherCondition(*fc)
	}
	return fu
}

// SetDateTime sets the "dateTime" field.
func (fu *ForecastUpdate) SetDateTime(t time.Time) *ForecastUpdate {
	fu.mutation.SetDateTime(t)
	return fu
}

// SetNillableDateTime sets the "dateTime" field if the given value is not nil.
func (fu *ForecastUpdate) SetNillableDateTime(t *time.Time) *ForecastUpdate {
	if t != nil {
		fu.SetDateTime(*t)
	}
	return fu
}

// SetRegionID sets the "region" edge to the Region entity by ID.
func (fu *ForecastUpdate) SetRegionID(id int64) *ForecastUpdate {
	fu.mutation.SetRegionID(id)
	return fu
}

// SetRegion sets the "region" edge to the Region entity.
func (fu *ForecastUpdate) SetRegion(r *Region) *ForecastUpdate {
	return fu.SetRegionID(r.ID)
}

// SetRegionWeatherID sets the "regionWeather" edge to the Weather entity by ID.
func (fu *ForecastUpdate) SetRegionWeatherID(id int64) *ForecastUpdate {
	fu.mutation.SetRegionWeatherID(id)
	return fu
}

// SetNillableRegionWeatherID sets the "regionWeather" edge to the Weather entity by ID if the given value is not nil.
func (fu *ForecastUpdate) SetNillableRegionWeatherID(id *int64) *ForecastUpdate {
	if id != nil {
		fu = fu.SetRegionWeatherID(*id)
	}
	return fu
}

// SetRegionWeather sets the "regionWeather" edge to the Weather entity.
func (fu *ForecastUpdate) SetRegionWeather(w *Weather) *ForecastUpdate {
	return fu.SetRegionWeatherID(w.ID)
}

// Mutation returns the ForecastMutation object of the builder.
func (fu *ForecastUpdate) Mutation() *ForecastMutation {
	return fu.mutation
}

// ClearRegion clears the "region" edge to the Region entity.
func (fu *ForecastUpdate) ClearRegion() *ForecastUpdate {
	fu.mutation.ClearRegion()
	return fu
}

// ClearRegionWeather clears the "regionWeather" edge to the Weather entity.
func (fu *ForecastUpdate) ClearRegionWeather() *ForecastUpdate {
	fu.mutation.ClearRegionWeather()
	return fu
}

// Save executes the query and returns the number of nodes affected by the update operation.
func (fu *ForecastUpdate) Save(ctx context.Context) (int, error) {
	return withHooks(ctx, fu.sqlSave, fu.mutation, fu.hooks)
}

// SaveX is like Save, but panics if an error occurs.
func (fu *ForecastUpdate) SaveX(ctx context.Context) int {
	affected, err := fu.Save(ctx)
	if err != nil {
		panic(err)
	}
	return affected
}

// Exec executes the query.
func (fu *ForecastUpdate) Exec(ctx context.Context) error {
	_, err := fu.Save(ctx)
	return err
}

// ExecX is like Exec, but panics if an error occurs.
func (fu *ForecastUpdate) ExecX(ctx context.Context) {
	if err := fu.Exec(ctx); err != nil {
		panic(err)
	}
}

// check runs all checks and user-defined validators on the builder.
func (fu *ForecastUpdate) check() error {
	if v, ok := fu.mutation.WindSpeed(); ok {
		if err := forecast.WindSpeedValidator(v); err != nil {
			return &ValidationError{Name: "windSpeed", err: fmt.Errorf(`ent: validator failed for field "Forecast.windSpeed": %w`, err)}
		}
	}
	if v, ok := fu.mutation.PrecipitationAmount(); ok {
		if err := forecast.PrecipitationAmountValidator(v); err != nil {
			return &ValidationError{Name: "precipitationAmount", err: fmt.Errorf(`ent: validator failed for field "Forecast.precipitationAmount": %w`, err)}
		}
	}
	if v, ok := fu.mutation.WeatherCondition(); ok {
		if err := forecast.WeatherConditionValidator(v); err != nil {
			return &ValidationError{Name: "weatherCondition", err: fmt.Errorf(`ent: validator failed for field "Forecast.weatherCondition": %w`, err)}
		}
	}
	if _, ok := fu.mutation.RegionID(); fu.mutation.RegionCleared() && !ok {
		return errors.New(`ent: clearing a required unique edge "Forecast.region"`)
	}
	return nil
}

func (fu *ForecastUpdate) sqlSave(ctx context.Context) (n int, err error) {
	if err := fu.check(); err != nil {
		return n, err
	}
	_spec := sqlgraph.NewUpdateSpec(forecast.Table, forecast.Columns, sqlgraph.NewFieldSpec(forecast.FieldID, field.TypeInt64))
	if ps := fu.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := fu.mutation.Temperature(); ok {
		_spec.SetField(forecast.FieldTemperature, field.TypeFloat64, value)
	}
	if value, ok := fu.mutation.AddedTemperature(); ok {
		_spec.AddField(forecast.FieldTemperature, field.TypeFloat64, value)
	}
	if value, ok := fu.mutation.WindSpeed(); ok {
		_spec.SetField(forecast.FieldWindSpeed, field.TypeFloat64, value)
	}
	if value, ok := fu.mutation.AddedWindSpeed(); ok {
		_spec.AddField(forecast.FieldWindSpeed, field.TypeFloat64, value)
	}
	if fu.mutation.WindSpeedCleared() {
		_spec.ClearField(forecast.FieldWindSpeed, field.TypeFloat64)
	}
	if value, ok := fu.mutation.PrecipitationAmount(); ok {
		_spec.SetField(forecast.FieldPrecipitationAmount, field.TypeFloat64, value)
	}
	if value, ok := fu.mutation.AddedPrecipitationAmount(); ok {
		_spec.AddField(forecast.FieldPrecipitationAmount, field.TypeFloat64, value)
	}
	if fu.mutation.PrecipitationAmountCleared() {
		_spec.ClearField(forecast.FieldPrecipitationAmount, field.TypeFloat64)
	}
	if value, ok := fu.mutation.WeatherCondition(); ok {
		_spec.SetField(forecast.FieldWeatherCondition, field.TypeEnum, value)
	}
	if value, ok := fu.mutation.DateTime(); ok {
		_spec.SetField(forecast.FieldDateTime, field.TypeTime, value)
	}
	if fu.mutation.RegionCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   forecast.RegionTable,
			Columns: []string{forecast.RegionColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(region.FieldID, field.TypeInt64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := fu.mutation.RegionIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   forecast.RegionTable,
			Columns: []string{forecast.RegionColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(region.FieldID, field.TypeInt64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if fu.mutation.RegionWeatherCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   forecast.RegionWeatherTable,
			Columns: []string{forecast.RegionWeatherColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(weather.FieldID, field.TypeInt64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := fu.mutation.RegionWeatherIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   forecast.RegionWeatherTable,
			Columns: []string{forecast.RegionWeatherColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(weather.FieldID, field.TypeInt64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if n, err = sqlgraph.UpdateNodes(ctx, fu.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{forecast.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return 0, err
	}
	fu.mutation.done = true
	return n, nil
}

// ForecastUpdateOne is the builder for updating a single Forecast entity.
type ForecastUpdateOne struct {
	config
	fields   []string
	hooks    []Hook
	mutation *ForecastMutation
}

// SetTemperature sets the "temperature" field.
func (fuo *ForecastUpdateOne) SetTemperature(f float64) *ForecastUpdateOne {
	fuo.mutation.ResetTemperature()
	fuo.mutation.SetTemperature(f)
	return fuo
}

// SetNillableTemperature sets the "temperature" field if the given value is not nil.
func (fuo *ForecastUpdateOne) SetNillableTemperature(f *float64) *ForecastUpdateOne {
	if f != nil {
		fuo.SetTemperature(*f)
	}
	return fuo
}

// AddTemperature adds f to the "temperature" field.
func (fuo *ForecastUpdateOne) AddTemperature(f float64) *ForecastUpdateOne {
	fuo.mutation.AddTemperature(f)
	return fuo
}

// SetWindSpeed sets the "windSpeed" field.
func (fuo *ForecastUpdateOne) SetWindSpeed(f float64) *ForecastUpdateOne {
	fuo.mutation.ResetWindSpeed()
	fuo.mutation.SetWindSpeed(f)
	return fuo
}

// SetNillableWindSpeed sets the "windSpeed" field if the given value is not nil.
func (fuo *ForecastUpdateOne) SetNillableWindSpeed(f *float64) *ForecastUpdateOne {
	if f != nil {
		fuo.SetWindSpeed(*f)
	}
	return fuo
}

// AddWindSpeed adds f to the "windSpeed" field.
func (fuo *ForecastUpdateOne) AddWindSpeed(f float64) *ForecastUpdateOne {
	fuo.mutation.AddWindSpeed(f)
	return fuo
}

// ClearWindSpeed clears the value of the "windSpeed" field.
func (fuo *ForecastUpdateOne) ClearWindSpeed() *ForecastUpdateOne {
	fuo.mutation.ClearWindSpeed()
	return fuo
}

// SetPrecipitationAmount sets the "precipitationAmount" field.
func (fuo *ForecastUpdateOne) SetPrecipitationAmount(f float64) *ForecastUpdateOne {
	fuo.mutation.ResetPrecipitationAmount()
	fuo.mutation.SetPrecipitationAmount(f)
	return fuo
}

// SetNillablePrecipitationAmount sets the "precipitationAmount" field if the given value is not nil.
func (fuo *ForecastUpdateOne) SetNillablePrecipitationAmount(f *float64) *ForecastUpdateOne {
	if f != nil {
		fuo.SetPrecipitationAmount(*f)
	}
	return fuo
}

// AddPrecipitationAmount adds f to the "precipitationAmount" field.
func (fuo *ForecastUpdateOne) AddPrecipitationAmount(f float64) *ForecastUpdateOne {
	fuo.mutation.AddPrecipitationAmount(f)
	return fuo
}

// ClearPrecipitationAmount clears the value of the "precipitationAmount" field.
func (fuo *ForecastUpdateOne) ClearPrecipitationAmount() *ForecastUpdateOne {
	fuo.mutation.ClearPrecipitationAmount()
	return fuo
}

// SetWeatherCondition sets the "weatherCondition" field.
func (fuo *ForecastUpdateOne) SetWeatherCondition(fc forecast.WeatherCondition) *ForecastUpdateOne {
	fuo.mutation.SetWeatherCondition(fc)
	return fuo
}

// SetNillableWeatherCondition sets the "weatherCondition" field if the given value is not nil.
func (fuo *ForecastUpdateOne) SetNillableWeatherCondition(fc *forecast.WeatherCondition) *ForecastUpdateOne {
	if fc != nil {
		fuo.SetWeatherCondition(*fc)
	}
	return fuo
}

// SetDateTime sets the "dateTime" field.
func (fuo *ForecastUpdateOne) SetDateTime(t time.Time) *ForecastUpdateOne {
	fuo.mutation.SetDateTime(t)
	return fuo
}

// SetNillableDateTime sets the "dateTime" field if the given value is not nil.
func (fuo *ForecastUpdateOne) SetNillableDateTime(t *time.Time) *ForecastUpdateOne {
	if t != nil {
		fuo.SetDateTime(*t)
	}
	return fuo
}

// SetRegionID sets the "region" edge to the Region entity by ID.
func (fuo *ForecastUpdateOne) SetRegionID(id int64) *ForecastUpdateOne {
	fuo.mutation.SetRegionID(id)
	return fuo
}

// SetRegion sets the "region" edge to the Region entity.
func (fuo *ForecastUpdateOne) SetRegion(r *Region) *ForecastUpdateOne {
	return fuo.SetRegionID(r.ID)
}

// SetRegionWeatherID sets the "regionWeather" edge to the Weather entity by ID.
func (fuo *ForecastUpdateOne) SetRegionWeatherID(id int64) *ForecastUpdateOne {
	fuo.mutation.SetRegionWeatherID(id)
	return fuo
}

// SetNillableRegionWeatherID sets the "regionWeather" edge to the Weather entity by ID if the given value is not nil.
func (fuo *ForecastUpdateOne) SetNillableRegionWeatherID(id *int64) *ForecastUpdateOne {
	if id != nil {
		fuo = fuo.SetRegionWeatherID(*id)
	}
	return fuo
}

// SetRegionWeather sets the "regionWeather" edge to the Weather entity.
func (fuo *ForecastUpdateOne) SetRegionWeather(w *Weather) *ForecastUpdateOne {
	return fuo.SetRegionWeatherID(w.ID)
}

// Mutation returns the ForecastMutation object of the builder.
func (fuo *ForecastUpdateOne) Mutation() *ForecastMutation {
	return fuo.mutation
}

// ClearRegion clears the "region" edge to the Region entity.
func (fuo *ForecastUpdateOne) ClearRegion() *ForecastUpdateOne {
	fuo.mutation.ClearRegion()
	return fuo
}

// ClearRegionWeather clears the "regionWeather" edge to the Weather entity.
func (fuo *ForecastUpdateOne) ClearRegionWeather() *ForecastUpdateOne {
	fuo.mutation.ClearRegionWeather()
	return fuo
}

// Where appends a list predicates to the ForecastUpdate builder.
func (fuo *ForecastUpdateOne) Where(ps ...predicate.Forecast) *ForecastUpdateOne {
	fuo.mutation.Where(ps...)
	return fuo
}

// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (fuo *ForecastUpdateOne) Select(field string, fields ...string) *ForecastUpdateOne {
	fuo.fields = append([]string{field}, fields...)
	return fuo
}

// Save executes the query and returns the updated Forecast entity.
func (fuo *ForecastUpdateOne) Save(ctx context.Context) (*Forecast, error) {
	return withHooks(ctx, fuo.sqlSave, fuo.mutation, fuo.hooks)
}

// SaveX is like Save, but panics if an error occurs.
func (fuo *ForecastUpdateOne) SaveX(ctx context.Context) *Forecast {
	node, err := fuo.Save(ctx)
	if err != nil {
		panic(err)
	}
	return node
}

// Exec executes the query on the entity.
func (fuo *ForecastUpdateOne) Exec(ctx context.Context) error {
	_, err := fuo.Save(ctx)
	return err
}

// ExecX is like Exec, but panics if an error occurs.
func (fuo *ForecastUpdateOne) ExecX(ctx context.Context) {
	if err := fuo.Exec(ctx); err != nil {
		panic(err)
	}
}

// check runs all checks and user-defined validators on the builder.
func (fuo *ForecastUpdateOne) check() error {
	if v, ok := fuo.mutation.WindSpeed(); ok {
		if err := forecast.WindSpeedValidator(v); err != nil {
			return &ValidationError{Name: "windSpeed", err: fmt.Errorf(`ent: validator failed for field "Forecast.windSpeed": %w`, err)}
		}
	}
	if v, ok := fuo.mutation.PrecipitationAmount(); ok {
		if err := forecast.PrecipitationAmountValidator(v); err != nil {
			return &ValidationError{Name: "precipitationAmount", err: fmt.Errorf(`ent: validator failed for field "Forecast.precipitationAmount": %w`, err)}
		}
	}
	if v, ok := fuo.mutation.WeatherCondition(); ok {
		if err := forecast.WeatherConditionValidator(v); err != nil {
			return &ValidationError{Name: "weatherCondition", err: fmt.Errorf(`ent: validator failed for field "Forecast.weatherCondition": %w`, err)}
		}
	}
	if _, ok := fuo.mutation.RegionID(); fuo.mutation.RegionCleared() && !ok {
		return errors.New(`ent: clearing a required unique edge "Forecast.region"`)
	}
	return nil
}

func (fuo *ForecastUpdateOne) sqlSave(ctx context.Context) (_node *Forecast, err error) {
	if err := fuo.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(forecast.Table, forecast.Columns, sqlgraph.NewFieldSpec(forecast.FieldID, field.TypeInt64))
	id, ok := fuo.mutation.ID()
	if !ok {
		return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Forecast.id" for update`)}
	}
	_spec.Node.ID.Value = id
	if fields := fuo.fields; len(fields) > 0 {
		_spec.Node.Columns = make([]string, 0, len(fields))
		_spec.Node.Columns = append(_spec.Node.Columns, forecast.FieldID)
		for _, f := range fields {
			if !forecast.ValidColumn(f) {
				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
			}
			if f != forecast.FieldID {
				_spec.Node.Columns = append(_spec.Node.Columns, f)
			}
		}
	}
	if ps := fuo.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := fuo.mutation.Temperature(); ok {
		_spec.SetField(forecast.FieldTemperature, field.TypeFloat64, value)
	}
	if value, ok := fuo.mutation.AddedTemperature(); ok {
		_spec.AddField(forecast.FieldTemperature, field.TypeFloat64, value)
	}
	if value, ok := fuo.mutation.WindSpeed(); ok {
		_spec.SetField(forecast.FieldWindSpeed, field.TypeFloat64, value)
	}
	if value, ok := fuo.mutation.AddedWindSpeed(); ok {
		_spec.AddField(forecast.FieldWindSpeed, field.TypeFloat64, value)
	}
	if fuo.mutation.WindSpeedCleared() {
		_spec.ClearField(forecast.FieldWindSpeed, field.TypeFloat64)
	}
	if value, ok := fuo.mutation.PrecipitationAmount(); ok {
		_spec.SetField(forecast.FieldPrecipitationAmount, field.TypeFloat64, value)
	}
	if value, ok := fuo.mutation.AddedPrecipitationAmount(); ok {
		_spec.AddField(forecast.FieldPrecipitationAmount, field.TypeFloat64, value)
	}
	if fuo.mutation.PrecipitationAmountCleared() {
		_spec.ClearField(forecast.FieldPrecipitationAmount, field.TypeFloat64)
	}
	if value, ok := fuo.mutation.WeatherCondition(); ok {
		_spec.SetField(forecast.FieldWeatherCondition, field.TypeEnum, value)
	}
	if value, ok := fuo.mutation.DateTime(); ok {
		_spec.SetField(forecast.FieldDateTime, field.TypeTime, value)
	}
	if fuo.mutation.RegionCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   forecast.RegionTable,
			Columns: []string{forecast.RegionColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(region.FieldID, field.TypeInt64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := fuo.mutation.RegionIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   forecast.RegionTable,
			Columns: []string{forecast.RegionColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(region.FieldID, field.TypeInt64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if fuo.mutation.RegionWeatherCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   forecast.RegionWeatherTable,
			Columns: []string{forecast.RegionWeatherColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(weather.FieldID, field.TypeInt64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := fuo.mutation.RegionWeatherIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   forecast.RegionWeatherTable,
			Columns: []string{forecast.RegionWeatherColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(weather.FieldID, field.TypeInt64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	_node = &Forecast{config: fuo.config}
	_spec.Assign = _node.assignValues
	_spec.ScanValues = _node.scanValues
	if err = sqlgraph.UpdateNode(ctx, fuo.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{forecast.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	fuo.mutation.done = true
	return _node, nil
}
